package com.irdstudio.tdp.executor.rest.job;

import com.irdstudio.tdp.executor.core.dao.BatInstBatchDao;
import com.irdstudio.tdp.executor.core.dao.BatInstTaskDao;
import com.irdstudio.tdp.executor.core.dao.domain.SSrvsCronConf;
import com.irdstudio.tdp.executor.core.tinycore.jdbc.dbcp.TConnPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;

public class MpToHistory implements ScheduleJob {
    private static final Logger logger = LoggerFactory.getLogger(MpToHistory.class);

    @Override
    public void doExcetue(Connection conn, SSrvsCronConf conf) throws SQLException {
        try{
            conn = TConnPool.getDefaultPool().getConnection();
            BatInstBatchDao bpaInstInfoDao=new BatInstBatchDao(conn);
            bpaInstInfoDao.recordTransfer();
            bpaInstInfoDao.deleteRecord();
            //将bpa_inst_task表七天前的数据转移到历史表
            BatInstTaskDao bpaInstTaskDao=new BatInstTaskDao(conn);
            bpaInstTaskDao.recordTransfer();
            bpaInstTaskDao.deleteRecord();
        }catch (SQLException e) {
            throw new SQLException(e.getMessage());
        } catch (Exception e) {
            throw new SQLException(e.getMessage());
        } finally {
            TConnPool.getDefaultPool().releaseConnection(conn);
        }
    }
}
